<template>
  <div class="reply-buyers">
    <h2>Reply to Buyers</h2>
    <div v-if="messages.length === 0" class="empty-messages">
      <p>No messages yet</p>
    </div>
    <div v-else class="message-list">
      <div v-for="message in messages" :key="message.id" class="message-card">
        <p>Buyer: {{ message.buyerName }}</p>
        <p>Message: {{ message.content }}</p>
        <el-input v-model="message.reply" type="textarea" placeholder="Reply to buyer" />
        <el-button type="primary" size="small" @click="sendReply(message)">Send Reply</el-button>
        <el-button type="danger" size="small" @click="deleteMessage(message)">Delete</el-button>
        <!-- 添加回复内容展示区域 -->
        <div v-if="message.replyContent" class="reply-content">
          <p><strong>Your Reply:</strong> {{ message.replyContent }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ReplyBuyers',
  data() {
    return {
      messages: [
        { id: 1, buyerName: 'Buyer A', content: 'When will my order be shipped?', reply: '', replyContent: '' },
        { id: 2, buyerName: 'Buyer B', content: 'Is this product available in blue?', reply: '', replyContent: '' },
      ],
    };
  },
  methods: {
    sendReply(message) {
      if (!message.reply) {
        alert('Please enter a reply');
        return;
      }
      // 将回复内容保存到 replyContent 中
      message.replyContent = message.reply;
      alert(`Reply sent to ${message.buyerName}`);
      message.reply = '';
    },
    deleteMessage(message) {
      this.messages = this.messages.filter((m) => m.id !== message.id);
      alert('Message deleted successfully');
    },
  },
};
</script>

<style scoped>
.reply-buyers {
  background-color: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.message-list {
  display: grid;
  gap: 20px;
}

.message-card {
  background-color: #fff;
  border-radius: 8px;
  padding: 15px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.message-card p {
  font-weight: bold;
  color: #333;
}

.empty-messages {
  text-align: center;
  color: #888;
}

.reply-content {
  margin-top: 10px;
  padding: 10px;
  background-color: #f9f9f9;
  border-radius: 4px;
  border: 1px solid #eee;
}

.reply-content p {
  margin: 0;
  color: #555;
}
</style>